export default {
  data() {
    return {
      result: ["a"],
      id: "",
      lisinfo: "",
      orTap: true,
      timerSet: null,
      newCoupon: false
    };
  },
  methods: {
    // 是否已经核销
    async checkStatus(id) {
      let json = {
        record_id: id
      };
      let { data, msg, result } = await $http.post("plugin.write-off-coupons.Frontend.controllers.code.get-status", json, "");
      if (result) {
        if (!data.status) {
          this.getList(id);
        } else {
          this.$dialog.alert({ message: "已核销" });
        }
      } else {
        this.$dialog.alert({ message: msg });
      }
    },
    getList(id) {
      var that = this;
      $http.get("plugin.write-off-coupons.Frontend.controllers.write-off.index", { record_id: id }, "正在获取").then(
        response => {
          if (response.result == 1) {
            that.lisinfo = response.data;
          } else {
            that.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // error callback
        }
      );
    },
    tapSure() {
      var that = this;
      if (this.fun.isTextEmpty(that.lisinfo)) {
        return;
      }
      $http.get("plugin.write-off-coupons.Frontend.controllers.write-off.handle", { record_id: that.id }, "正在获取").then(
        response => {
          that.$dialog.alert({ message: response.msg });
          if (response.result == 1) {
            this.orTap = false;
          }
        },
        function(response) {
          // error callback
        }
      );
    },
    init() {
      this.orTap = true;
    },
    async getData() {
      let { data, msg, result } = await $http.post("plugin.new-coupon.frontend.controllers.member-coupon.write-off-page", { code: this.$route.query.code }, "");
      if (result) {
        this.lisinfo = data;
      } else {
        this.$toast(msg);
      }
    },
    async writeOffTap() {
      let { data, msg, result } = await $http.post("plugin.new-coupon.frontend.controllers.member-coupon.write-off", { code: this.$route.query.code }, "");
      this.$toast(msg);
    }
  },
  activated() {
    this.init();
    let id = this.$route.query.record_id;
    this.id = id;
    if (this.$route.name == "new_CouponCheckList") {
      this.newCoupon = true;
      this.getData();
    } else {
      this.checkStatus(id);
    }
  },
  mounted() {},
  components: { }
};
